# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Rasmus Thomsen <oss@cogitri.dev>
pkgname=gvfs
pkgver=1.44.1
pkgrel=0
pkgdesc="Backends for the gio framework in GLib"
url="https://wiki.gnome.org/Projects/gvfs"
arch="all"
license="LGPL-2.0-or-later"
depends="gsettings-desktop-schemas dbus:org.freedesktop.Secrets"
makedepends="fuse3-dev libgudev-dev expat-dev samba-dev libxml2-dev
	libsoup-dev avahi-dev libarchive-dev udisks2-dev libgphoto2-dev
	libcdio-paranoia-dev libgcrypt-dev libxslt-dev docbook-xsl
	libmtp-dev gcr-dev libcap-dev libsecret-dev libnfs-dev meson
	openssh-client libusb-dev gnome-online-accounts-dev libimobiledevice-dev
	libbluray-dev libgdata-dev gsettings-desktop-schemas-dev"
triggers="$pkgname.trigger=/usr/libexec/gvfs"
subpackages="$pkgname-dev $pkgname-lang
	$pkgname-afc
	$pkgname-afp
	$pkgname-archive
	$pkgname-avahi
	$pkgname-cdda
	$pkgname-dav
	$pkgname-fuse
	$pkgname-gphoto2
	$pkgname-goa
	$pkgname-mtp
	$pkgname-nfs
	$pkgname-smb
	"
source="https://download.gnome.org/sources/gvfs/${pkgver%.*}/gvfs-$pkgver.tar.xz"

# secfixes:
#   1.40.2-r0:
#     - CVE-2019-12795
#     - CVE-2019-12449
#     - CVE-2019-12447
#     - CVE-2019-12448

build() {
	meson \
		--buildtype=plain \
		--prefix=/usr \
		--libexecdir=/usr/libexec/gvfs \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		-Dsystemduserunitdir=no \
		-Dtmpfilesdir=no \
		-Dlogind=false \
		. output


	ninja -C output
}

check() {
	ninja -C output test
}

package() {
	DESTDIR="$pkgdir" ninja -C output install
}

_mv_files() {
	local i
	for i in "$@"; do
		mkdir -p "$subpkgdir"/${i%/*}
		mv "$pkgdir"/$i "$subpkgdir"/$i
	done
}

fuse() {
	pkgdesc="FUSE support for gvfs"
	cd "$pkgdir"
	_mv_files usr/libexec/gvfs/gvfsd-fuse
}

smb() {
	pkgdesc="Windows fileshare support for gvfs"
	cd "$pkgdir"
	_mv_files \
		usr/libexec/gvfs/gvfsd-smb* \
		usr/share/gvfs/mounts/smb* \
		usr/share/glib-*/schemas/org.gnome.system.smb.gschema.xml \
		usr/share/GConf/gsettings/gvfs-smb.convert
}

mtp() {
	pkgdesc="MTP support for gvfs"
	cd "$pkgdir"
	_mv_files usr/libexec/gvfs/gvfsd-mtp
}

archive() {
	pkgdesc="Archiving support for gvfs"
	cd "$pkgdir"
	_mv_files \
		usr/libexec/gvfs/gvfsd-archive* \
		usr/share/gvfs/mounts/archive*
}

obexftp() {
	pkgdesc="ObexFTP support for gvfs"
	cd "$pkgdir"
	_mv_files \
		usr/libexec/gvfs/gvfsd-obex* \
		usr/share/gvfs/mounts/obex*
}

gphoto2() {
	pkgdesc="gphoto2 support for gvfs"
	cd "$pkgdir"
	_mv_files \
		usr/libexec/gvfs/gvfs*gphoto* \
		usr/share/gvfs/*/gphoto* \
		usr/share/dbus*/services/*GPhoto*
}

afp() {
	pkgdesc="AFP support for gvfs"
	cd "$pkgdir"
	_mv_files \
		usr/libexec/gvfs/gvfs*afp* \
		usr/share/gvfs/*/afp*
}

avahi() {
	pkgdesc="DNS-SD support for gvfs"
	cd "$pkgdir"
	_mv_files \
		usr/libexec/gvfs/gvfs*dns* \
		usr/share/gvfs/mounts/dns-sd.mount \
		usr/share/glib-*/schemas/org.gnome.system.dns_sd.gschema.xml \
		usr/share/GConf/gsettings/gvfs-dns-sd.convert
}

cdda() {
	pkgdesc="CDDA support for gvfs"
	cd "$pkgdir"
	_mv_files \
		usr/share/gvfs/mounts/cdda.mount \
		usr/libexec/gvfs/gvfsd-cdda
}

dav() {
	pkgdesc="WebDAV support for gvfs"
	cd "$pkgdir"
	_mv_files \
		usr/share/gvfs/mounts/dav.mount \
		usr/share/gvfs/mounts/dav+sd.mount \
		usr/libexec/gvfs/gvfsd-dav
}

nfs() {
	pkgdesc="NFS support for gvfs"
	cd "$pkgdir"
	_mv_files \
		usr/share/gvfs/mounts/nfs.mount \
		usr/libexec/gvfs/gvfsd-nfs
}

goa() {
	pkgdesc="GNOME Online Accounts support for gvfs"
	cd "$pkgdir"
	_mv_files \
		usr/libexec/gvfs/gvfs-goa-volume-monitor \
		usr/libexec/gvfs/gvfsd-google \
		usr/share/gvfs/mounts/google.mount \
		usr/share/dbus-1/services/org.gtk.vfs.GoaVolumeMonitor.service \
		usr/share/gvfs/remote-volume-monitors/goa.monitor
}

afc() {
	pkgdesc="Apple mobile devices support for gvfs"
	cd "$pkgdir"
	_mv_files \
		usr/libexec/gvfs/gvfsd-afc \
		usr/libexec/gvfs/gvfs-afc-volume-monitor \
		usr/share/dbus-1/services/org.gtk.vfs.AfcVolumeMonitor.service \
		usr/share/gvfs/remote-volume-monitors/afc.monitor
}
sha512sums="d936e70e6daa6a7494e5cc333a53afe82b601e34e2e54b207d9a4aefdc35dd068997832be750a6857144a48fa37065cb7e6b25378952007b06988ad07dfc6006  gvfs-1.44.1.tar.xz"
